package cn.com.haopy.dataes.es.service;


import cn.com.haopy.dataes.es.entity.EsPatient;
import cn.com.haopy.dataes.es.entity.EsUserPatient;
import cn.com.haopy.dataes.es.mapper.EsUserPatientMapper;
import cn.easyes.core.conditions.LambdaEsQueryWrapper;
import cn.easyes.core.toolkit.EsWrappers;
import cn.easyes.core.toolkit.FieldUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class EsUserPatientServices {
    @Resource
    private EsUserPatientMapper esUserPatientMapper;


    public Integer insert(EsUserPatient patient) {
        return esUserPatientMapper.insert(patient);
    }


    public List<EsUserPatient> queryListBySearchKey(String search) {

        // 其中嵌套类的字段名称获取我们提供了工具类FieldUtils.val帮助用户通过lambda函数式获取字段名称,当然如果不想用也可以直接传字符串
        LambdaEsQueryWrapper wrapper = EsWrappers.lambdaQuery(EsUserPatient.class)
                //.match(EsUserPatient::getId, 1)
                .nestedMatch(EsUserPatient::getPatient, FieldUtils.val(EsPatient::getName), search);
        List<EsUserPatient> list = esUserPatientMapper.selectList(wrapper);
        return list;

    }


}
